<div class="divmain">
<table width="100%" id="cusfrmproduct_tblinfo" class="tblInfo">
<tr>
<td valign="top" class="width25"  >
<div >
<table class="info" id="cusfrmproduct_info">
<tr>
<td>
<div id="cusfrmproduct_divleft" class="divleft">
<table class="width100">
       <tr >
         <td align="right" width="43%" class="lblRequired"><b>Loại sản phẩm:</b></td>
         <td>
             <div id="cusfrmproduct_tdmenuparent">
                 <select id="cusfrmproduct_cbbMenuParent" class="width100">
                   <option value="-1">-- Chọn --</option>
                 </select>
             </div>
         </td>
       </tr>
       <tr>
         <td align="right" width="43%" class="lblRequired"><b>Tên :</b></td>
         <td><input maxlength="30" type="text" class="txtRequired" id="cusfrmproduct_txtnamemenuVi" value="" style="width:180px"/></td>
       </tr>
      <tr>
         <td align="right"  class="lblRequired"><b>Đơn vị tính:</b></td>
         <td id="cusfrmproduct_tdUnit">
             <select class="width100"><option>-Chọn-</option></select>
         </td>
       </tr> 
       
       <tr>
         <td align="right" class="lblRequired"><b>Giá bán:</b></td>
         <td>
             <input maxlength="9" type="text" class="isNumber txtRequired txtTien" name="txt_price_menu" id="cusfrmproduct_txtprice" value="" style="width:180px"/>
         </td>
       </tr>
       <tr>
         <td align="right"><b>Giá mua:</b></td>
         <td>
             <input type="text" maxlength="9" class="isNumber txtTien" name="txt_pricebuy" id="cusfrmproduct_txtpricebuy" value="" style="width:180px"/>
         </td>
       </tr>               
       <tr>
         <td align="right"><b>Quản lí tồn kho:</b></td>
         <td>
             <input type="checkbox" id="cusfrmproduct_chkquanlity"  checked="checked"/>
         </td>
       </tr> 
       
       <tr>
         <td colspan="2"> <button id="cusfrmproduct_addFromDefault" onclick="cusfrmproduct_addFromDefault()" class="width100">Thêm sản phẩm từ danh sách hệ thống </button>   </td>
         
       </tr>
 
</table>


    <div class="divactionbuton">

        <input type="hidden" id='cusfrmproduct_hdEdit' value="0"/>
        <input type="hidden" id='cusfrmproduct_hdId' value=""/>
        <button class="save validate btnsave" id="cusfrmproduct_submit" type="button"> Thêm Mới </button>
        <button class="clear" type="reset" id="cusfrmproduct_clear"> Nhập Lại </button>
    </div>
</div>


</td>
</tr>
       
       <tr>
<td>
</td>
</tr>
</table>
</div>
</td>

<td class="clsmiddle"></td>
<td height="400" valign="top">
<div class="divGrid" id="cusfrmproduct_divGrid">
</div>

<div class="divDialog" id="cusfrmproduct_divAddProduct">
    <table class="tblDialog info" id="cusfrmproduct_tblAddProduct">
       <tr >
         <td align="right" width="43%" class="lblRequired"><b>Chọn loại sản phẩm:</b></td>
         <td id="cusfrmproduct_dftdmenuparent" >
             
                 <select id="cusfrmproduct_cbbMenuParentDefault" class="width100">
                   <option value="-1">-- Chọn --</option>
                 </select>
             
         </td>
       </tr>
              
        <tr>
            <td colspan="2" style="text-align:center"><font size="+1"> <b>Danh sánh sản phẩm từ hệ thống</b></font></td>
        </tr>
        
        <tr>
        <td colspan="2" id="cusfrmproduct_dftdproduct" class="lblRequired">
        
                     
        </td>
       
    </tr>

        <tr>
            <td class="alignCenter" colspan="2">                
                <button id="cusfrmproduct_dfsaveProduct" onclick="cusfrmproduct_dfsaveProduct()">Thêm vào</button>
                <button  class="cancelDialog">Đóng</button>
            </td></tr>
    </table>
</div>


</td>
<td class="clsend"></td>

</tr>
</table>
</div>
<script language="javascript">
changeWaiting(0); 
$(document).ready(function () {
    initForm('cusfrmproduct_tblinfo'); 
    initDivleft();
    
    $('#cusfrmproduct_divAddProduct').dialog({
        autoOpen: false,
        modal: true,
        width: 800,
        title: 'Danh sách sản phẩm trong hệ thống',
        resizable: true,
        overflow: 'auto'
    });
    $('.clspricesale').live('focus',function(){
        $(this).css('background-color','white');
    });
       
});


function cusfrmproduct_addFromDefault(){
    xajax_cusfrmproduct_dfloadproduct();
}

function cusfrmproduct_dfsaveProduct(){
    if($('#cusfrmproduct_cbbMenuParentDefault').val()==''){
        alert('Vui lòng chọn loại sản phẩm');
       $('#cusfrmproduct_cbbMenuParentDefault').focus();
       return false; 
    }
    var lendf = $('.clsdfproduct').find('.chkSelect:checked').length;
    if(lendf==0){
      alert('Vui lòng chọn sản phẩm cần thêm vào');
      return false;      
    }
    var strid = '';
    var strprice = '';
    var strpricebuy = '';
    var flg= false;
    var first_id ='';
    var strChk ='';
    $('.clspricesale').css('background-color','white');
    $('.clsdfproduct').find('.chkSelect:checked').each(function(){
        var arr = $(this).attr('id').split("_");
        $id = arr[2];
         
        var price = $('#cusfrmproduct_dfpricesale_'+$id).val();
        var pricebuy = $('#cusfrmproduct_dfpricebuy_'+$id).val();
        strid +=','+$id;
        strprice +=','+price;
        strpricebuy +=','+pricebuy;
        if($('#cusfrmproduct_dfchkquanlity_'+$id).attr('checked')=='checked'){
          strChk+=',1';  
        }else{
          strChk+=',0';    
        }
         
        if($('#cusfrmproduct_dfpricesale_'+$id).val()==''){
            if(!flg){
              first_id = $id;  
            }
          flg = true;
          $('#cusfrmproduct_dfpricesale_'+$id).css('background-color','yellow');
            
        } 
        
    });
    
    if(flg){
        alert('Vui lòng nhập giá bán cho sản phẩm đã chọn');
        $('#cusfrmproduct_dfpricesale_'+first_id).focus();
        return false;
    }
    var params = new Array();
    params['producttype']= $('#cusfrmproduct_cbbMenuParentDefault').val();
    params['strid']= strid;
    params['strprice']= strprice;
    params['strpricebuy']= strpricebuy;
    params['strChk']= strChk;
    xajax_cusfrmproduct_dfaddProduct(params);
    
}

xajax_cusfrmproduct_loadGrid();
xajax_cusfrmproduct_fillMenuParent();
xajax_cusfrmproduct_init();
</script>
